//
//  RHIntrodutionListCell.m
//  RuiHeAppApp
//
//  Created by Yan Chen on 2023/7/13.
//

#import "RHIntrodutionListCell.h"


@interface RHIntrodutionListCell()

@property (nonatomic, strong) UIImageView   *prductImgView;

@property (nonatomic, strong) QMUILabel     *typeLab;

@property (nonatomic, strong) QMUILabel     *descLab;

@property (nonatomic, strong) QMUIButton    *applyBtn;

@property (nonatomic, strong) QMUIButton    *moreBtn;


@end
@implementation RHIntrodutionListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        [self setupUI];
    }
    return self;
}

- (void)setupUI{
    [self setBackgroundColor:UIColor.clearColor];
    self.contentView.backgroundColor = UIColor.clearColor;
    
    UIView *bgV = [[UIView alloc] init];
    [bgV setBackgroundColor:UIColor.whiteColor];
    [bgV.layer setCornerRadius:8.0];
    [bgV.layer setMasksToBounds:YES];
    [self.contentView addSubview:bgV];
    
    [bgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_offset(0);
        make.left.mas_offset(15);
        make.right.mas_offset(-15);
        make.bottom.mas_offset(0);
    }];
    

    _prductImgView = [[UIImageView alloc] init];
    [_prductImgView setBackgroundColor:UIColor.whiteColor];
    _prductImgView.image = kImage(@"cooperation_pic");
    [bgV addSubview:_prductImgView];
    
    [_prductImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.mas_equalTo(0);
        make.height.mas_equalTo(165);
    }];
    
    UIView *view = [[UIView alloc] init];
    [view setBackgroundColor:[UIColor.blackColor colorWithAlphaComponent:0.2]];
    view.layer.cornerRadius = 8;
    view.layer.masksToBounds = YES;
    [_prductImgView addSubview:view];
    
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsZero);
    }];
    
    
    _typeLab = [[QMUILabel alloc]init];
    _typeLab.font = kBOLDIP7FONT(18);
    _typeLab.numberOfLines = 0;
    _typeLab.textColor = UIColor.whiteColor;
    _typeLab.textAlignment = NSTextAlignmentLeft;
    [_prductImgView addSubview:_typeLab];
    
    kWeakSelf;
    [_typeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(weakSelf.prductImgView);
        make.top.mas_equalTo(50);
     }];
    
    _descLab = [[QMUILabel alloc]init];
    _descLab.font = kSYSTEMFONT(13);
    _descLab.numberOfLines = 0;
    _descLab.textColor = [kCOLOR_HEX(@"3F4443") colorWithAlphaComponent:0.8];
    _descLab.textAlignment = NSTextAlignmentLeft;
    [bgV addSubview:_descLab];
    
    [_descLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.right.mas_equalTo(-10);
        make.top.equalTo(weakSelf.prductImgView.mas_bottom).offset(10);
        
     }];
    
    _applyBtn = [[QMUIButton alloc]init];
    [_applyBtn setTitle:@"Apply now" forState:UIControlStateNormal];
    [_applyBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    [_applyBtn setBackgroundColor:[CFMainColor colorWithAlphaComponent:0.9]];
    ViewRadius(_applyBtn, 5);
    _applyBtn.titleLabel.font = kSYSTEMFONT(13);
    [bgV addSubview:_applyBtn];
    [_applyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.contentView);
        make.width.mas_equalTo(110);
        make.height.mas_equalTo(40);
        make.top.equalTo(weakSelf.typeLab.mas_bottom).offset(30);
        
    }];
    
    [[_applyBtn rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(__kindof UIControl * _Nullable x) {
        
                
    }];
    
    _moreBtn = [[QMUIButton alloc]init];
    _moreBtn.hidden = YES;
    [_moreBtn setTitle:@"know more about >" forState:UIControlStateNormal];
    [_moreBtn setTitleColor:CFMainColor forState:UIControlStateNormal];
    [_moreBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];
    _moreBtn.titleLabel.font = kSYSTEMFONT(13);
    [bgV addSubview:_moreBtn];
    [_moreBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.descLab.mas_bottom).offset(0);
        make.right.mas_offset(-15);
        make.bottom.mas_equalTo(0);
        make.width.mas_equalTo(200);
        make.height.mas_equalTo(40);
    }];
    
    [[_moreBtn rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(__kindof UIControl * _Nullable x) {
        if(weakSelf.lernMoreBlock){
            weakSelf.lernMoreBlock();
        }
                
    }];
    
    [[_applyBtn rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(__kindof UIControl * _Nullable x) {
        if(weakSelf.applyBlock){
            weakSelf.applyBlock(weakSelf.idx);
        }
              
                
    }];
}

- (void)setTypeName:(NSString *)typeName{
    _typeName = typeName;
    [_typeLab setText:_typeName];
}

- (void)setTypeDes:(NSString *)typeDes{
    _typeDes = typeDes;
    [_descLab setText:_typeDes];
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
